export const user_info = 'user_info'
export const role_info = 'role_info'
export const sidebar_flag = 'sidebar_flag'
export const tag_list= 'tag_list'
import cryptoJS from 'crypto-js'


/**
 * 存储sessionStorage
 */
export function setSession (key, obj) {
  let value = JSON.stringify(obj)
  sessionStorage.setItem(key, value)
}

/**
 * 获取sessionStorage
 */
export function getSession (key) {
  let value = sessionStorage.getItem(key)
  let obj = {}
  if (value) {
    obj = JSON.parse(value)
  }
  return obj
}

/**
 * 校验邮箱
 */
export function validateEmail(email) {
  const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  return re.test(email)
}

/**
 * 校验手机号
 */
export function validatePhone (phone) {
  const re = /^1(3|4|5|7|8)\d{9}$/
  return re.test(phone)
}

/**
 * md5加盐密码
 */
export function signPwd (pwd) {
  return cryptoJS.MD5(pwd).toString()
}